<template>
  <div class="bubble" :class="heart?'heartbeat':''" @click="click">
    <span :class="heart?'heartbeat-text':''">{{ waterPercent }}%</span>
  </div>
</template>

<script>
export default {
  props: {
    percent: {//高度的百分比
      type: Number,
      default: 0.5
    },
    heart: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    waterPercent() {
      return parseFloat(this.percent * 100 + '').toFixed(0);
    },
  },
  methods: {
    click() {
      this.$emit('click')
    }
  }
}
</script>

<style lang="less">
@keyframes rotate2 {
  0% {
    transform: rotate(0deg) translateY(-2px);
  }
  100% {
    transform: rotate(360deg) translateY(-2px);
  }
}

.bubble {
  z-index: 2;
  opacity: 0.9;
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 100%;
  width: 40px;
  height: 40px;
  background-image: linear-gradient(45deg, #5698d3, #0080ff);
  color: white;
  font-size: 12px;
  font-weight: bold;
  box-shadow: 0 3px 2px 1px rgba(0, 0, 0, 0.2);
}

.bubble::before,
.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  margin-left: -20px;
  margin-top: -20px;
  width: 40px;
  height: 40px;
  border-radius: 100%;
  background-color: rgb(51, 149, 230);
  transform: translateY(-2px);
  z-index: -1;
}

.bubble::before {
  animation: rotate2 3s linear;
  animation-iteration-count: 5;
}

.bubble::after {
  animation: rotate2 2s linear;
  animation-iteration-count: 5;
}

.heartbeat-text {
  font-family: ZCOOL, serif;
  font-weight: bold;
}

.heartbeat {
  -webkit-animation: heartbeat 1.5s ease-in-out infinite both;
  animation: heartbeat 1.5s ease-in-out infinite both;
}

/* ----------------------------------------------
 * Generated by Animista on 2021-1-3 1:41:15
 * Licensed under FreeBSD License.
 * See http://animista.net/license for more info.
 * w: http://animista.net, t: @cssanimista
 * ---------------------------------------------- */

/**
 * ----------------------------------------
 * animation heartbeat
 * ----------------------------------------
 */
@-webkit-keyframes heartbeat {
  from {
    -webkit-transform: scale(1);
    transform: scale(1);
    -webkit-transform-origin: center center;
    transform-origin: center center;
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
  }
  10% {
    -webkit-transform: scale(0.91);
    transform: scale(0.91);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
  }
  17% {
    -webkit-transform: scale(0.98);
    transform: scale(0.98);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
  }
  33% {
    -webkit-transform: scale(0.87);
    transform: scale(0.87);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
  }
  45% {
    -webkit-transform: scale(1);
    transform: scale(1);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
  }
}

@keyframes heartbeat {
  from {
    -webkit-transform: scale(1);
    transform: scale(1);
    -webkit-transform-origin: center center;
    transform-origin: center center;
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
  }
  10% {
    -webkit-transform: scale(0.91);
    transform: scale(0.91);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
  }
  17% {
    -webkit-transform: scale(0.98);
    transform: scale(0.98);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
  }
  33% {
    -webkit-transform: scale(0.87);
    transform: scale(0.87);
    -webkit-animation-timing-function: ease-in;
    animation-timing-function: ease-in;
  }
  45% {
    -webkit-transform: scale(1);
    transform: scale(1);
    -webkit-animation-timing-function: ease-out;
    animation-timing-function: ease-out;
  }
}

</style>
